package compute_words;

import java.io.*;

public class Compute {
	public static void main(String args[]){
		int i,x=0;
		FileInputStream fin=null;
		PrintWriter pw=new PrintWriter(System.out,true);
		if(args.length!=1){
			pw.println("Please enter a correct filename.");
			return;
		}
		try{
			fin=new FileInputStream(args[0]);
			i=fin.read();
			do{
				if(Character.isLetter(i)){
					x++;
					do{
						i=fin.read();
					}while(Character.isLetter(i));
				}
				else{
					do{
						i=fin.read();
					}while(!(Character.isLetter(i)));
				}
			}while(i!=-1);
		}catch(FileNotFoundException e){
			pw.println("File Not Found.");
		}catch(IOException e){
			pw.println("An I/O Error Occurred");
		}finally{
			try{
				if(fin!=null)fin.close();
			}catch(IOException e){
				pw.println("Error Closing File");
			}
		}
		pw.println("This article contains "+x+" words.");
	}
}

